package com.softkey;

public class SoftKey2 {

	jsyunew3 j9;
    public SoftKey2()
	{
		j9=new  jsyunew3();
	}

	private String myhex(byte indata)
	{
		String outString;
		outString=String.format("%X",indata);
		if(outString.length()<2)outString="0"+outString;
		return outString;
	}

    private  long conver(byte temp){
        long tempInt = (int)temp;
        if(tempInt < 0){
            tempInt += 256;
        }
        return tempInt;
    }

    private int HexToInt(String s)
    {
        String [] hexch = { "0", "1", "2", "3", "4", "5", "6", "7",
						       "8", "9", "A", "B", "C", "D", "E", "F"};
        int i, j;
        int r, n, k;
        String ch;

        k = 1; r = 0;
        for (i = s.length(); i > 0; i--)
        {
            ch = s.substring(i - 1,  i-1+1);
            n = 0;
            for (j = 0; j < 16; j++)
            {
                if (ch.compareToIgnoreCase(hexch[j]) ==0 )
                {
                    n = j;
                }
            }
            r += (n * k);
            k *= 16;
        }
        return r;
    }


    public String  StrEnc(String InString , String Key)
    {

        byte [] b,outb;
        byte []temp_b=InString.getBytes();
        byte [] temp=new byte[8],outtemp=new byte[8];
        int n,i,nlen,outlen;
        String outString;

        nlen = temp_b.length;
        nlen=nlen+1;
        if( nlen < 8 )
            outlen = 8;
        else
            outlen = nlen;
        b=new byte[outlen];
        outb=new byte[outlen];

        for(n=0;n<nlen-1;n++)
        {
        	b[n]=temp_b[n];
        }

        outb=b.clone();

        for( n = 0; n<=outlen - 8 ;n=n+ 8)
        {
            for (i = 0; i < 8; i++) temp[i] = b[i + n];
            EnCode(temp, outtemp, Key);
            for( i = 0 ;i<8;i++) outb[i + n] = outtemp[i];
        }

        outString = "";
        for (n = 0 ;n<= outlen - 1;n++)
        {
            outString = outString +myhex(outb[n]) ;
        }
        return outString;
    }

    public String  StrDec(String InString , String Key)

    {

        byte [] b,outb;
        byte [] temp=new byte[8],outtemp=new byte[8];
        int n,i,nlen,outlen;
        String outString,temp_String;


        nlen = InString.length();
        if( nlen < 16 ) outlen = 16;
        outlen = nlen / 2;
        b=new byte[outlen];
        outb=new byte[outlen];

        i = 0;
        for (n = 1 ;n<= nlen ;n=n+2)
        {
            temp_String = InString.substring(n-1, n-1+2);
            b[i] = (byte)HexToInt(temp_String);
            i = i + 1;
        }

        outb=b.clone();

        for( n = 0; n<=outlen - 8 ;n=n+ 8)
        {
            for (i = 0; i < 8; i++) temp[i] = b[i + n];
            DeCode(temp, outtemp, Key);
            for( i = 0 ;i<8;i++) outb[i + n] = outtemp[i];
        }

        outString=new String(outb);
        outString=outString.trim();
        return outString;
    }

	public void EnCode(byte[] inb, byte[] outb,  String Key )
    {

		long cnDelta,y,z,a,b,c,d,temp_2;
		long [] buf=new long[16];
       int n,i,nlen;
       long sum;
       long temp,temp_1;
       long mask=4294967295L;

       String temp_String ;


       cnDelta = 2654435769L;
       sum = 0;

       nlen = Key.length();
       i = 0;
       for( n = 1 ;n<= nlen ;n=n+2)
       {
           temp_String =Key.substring(n-1, n-1+2);
           buf[i] =HexToInt(temp_String);
           i = i + 1;
       }
       a = 0 ; b = 0 ; c = 0 ; d = 0;
       for(n = 0;n<=3;n++)
       {
           a = (buf[n] << (n * 8)) | a;
           b = (buf[n + 4] << (n * 8)) | b;
           c = (buf[n + 4 + 4] << (n * 8)) | c;
           d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;
       }


       y = 0;
       z = 0;
       for(n = 0;n<=3;n++)
       {
           temp_2 = conver(inb[n]);
           y = (temp_2 << (n * 8)) | y;
           temp_2 = conver(inb[n + 4]);
           z = (temp_2 << (n * 8)) | z;
       }


       n = 32;

       while (n > 0)
       {
           sum = (cnDelta + sum)& mask;

           temp = (z << 4) & mask;
           temp = (temp + a) & mask;
           temp_1 = (z + sum) & mask;
           temp = (temp ^ temp_1) & mask;
           temp_1 = (z >> 5) & mask;
           temp_1 = (temp_1 + b) & mask;
           temp = (temp ^ temp_1) & mask;
           temp = (temp + y) & mask;
           y = temp & mask;
           /*y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); */

           temp = (y << 4) & mask;
           temp = (temp + c) & mask;
           temp_1 = (y + sum) & mask;
           temp = (temp ^ temp_1) & mask;
           temp_1 = (y >> 5) & mask;
           temp_1 = (temp_1 + d) & mask;
           temp = (temp ^ temp_1) & mask;
           temp = (z + temp) & mask;
           z = temp & mask;
           /* z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); */
           n = n - 1;

       }
       for(n = 0;n<=3;n++)
       {
           outb[n] = (byte)((y >>> (n * 8)) & 255);
           outb[n + 4] =(byte)((z >>> (n * 8)) & 255);
       }
    }

	public void DeCode(byte[] inb, byte[] outb,  String Key )
    {

		long cnDelta,y,z,a,b,c,d,temp_2;
		long [] buf=new long[16];
       int n,i,nlen;
       long sum;
       long temp,temp_1;

       long mask=4294967295L;


       String temp_String ;


       cnDelta = 2654435769L;
       sum = 3337565984L;

       nlen = Key.length();
       i = 0;
       for( n = 1 ;n<= nlen ;n=n+2)
       {
           temp_String =Key.substring(n-1, n-1+2);
           buf[i] =HexToInt(temp_String);
           i = i + 1;
       }
       a = 0 ; b = 0 ; c = 0 ; d = 0;
       for(n = 0;n<=3;n++)
       {
           a = (buf[n] << (n * 8)) | a;
           b = (buf[n + 4] << (n * 8)) | b;
           c = (buf[n + 4 + 4] << (n * 8)) | c;
           d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;
       }


       y = 0;
       z = 0;
       for(n = 0;n<=3;n++)
       {
           temp_2 = conver(inb[n]);
           y = (temp_2 << (n * 8)) | y;
           temp_2 = conver(inb[n + 4]);
           z = (temp_2 << (n * 8)) | z;
       }


       n = 32;

       while (n > 0)
       {


           temp = (y << 4) & mask;
           temp = (temp + c) & mask;
           temp_1 = (y + sum) & mask;
           temp = (temp ^ temp_1) & mask;
           temp_1 = (y >> 5) & mask;
           temp_1 = (temp_1 + d) & mask;
           temp = (temp ^ temp_1) & mask;
           temp = (z - temp) & mask;
           z = temp & mask;
           /* z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); */

           temp = (z << 4) & mask;
           temp = (temp + a) & mask;
           temp_1 = (z + sum) & mask;
           temp = (temp ^ temp_1) & mask;
           temp_1 = (z >> 5) & mask;
           temp_1 = (temp_1 + b) & mask;
           temp = (temp ^ temp_1) & mask;
           temp = (y - temp ) & mask;
           y = temp & mask;
           /*y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); */

           sum = (sum-cnDelta)& mask;
           n = n - 1;

       }
       for(n = 0;n<=3;n++)
       {
           outb[n] = (byte)((y >>> (n * 8)) & 255);
           outb[n + 4] =(byte)((z >>> (n * 8)) & 255);
       }
    }

	public  long get_LastError()
	{
		return j9.get_LastError();
	}

	public String FindPort(int start)
    {
        return j9.FindPort(start);
    }

   public int CheckKeyByFindort_2()
    {

        String DevicePath = "";
		DevicePath = j9.FindPort_2(0, 1, -1850055438);
		int ret = (int)j9.get_LastError();
		j9.CloseUsbHandle(DevicePath);
		return ret;
    }



    private String ReadStringEx(int addr, String DevicePath)
    {
        int nlen, ret;
        byte[] buf = new byte[1];

		ret = j9.YReadEx((short)addr, (short)1, "C7C1F46A", "73FA728C", DevicePath);
        if (ret != 0) return "";
		nlen = j9.GetBuf(0);

		return j9.NewReadString(addr + 1, nlen, "C7C1F46A", "73FA728C", DevicePath);

    }

    public int CheckKeyByReadEprom()
    {
        int n, ret;
        String DevicePath = "";
        String outString = "";

        for (n = 0; n < 255; n++)
        {
            DevicePath= j9.FindPort(n );
            if (j9.get_LastError() != 0) return (int)j9.get_LastError();
			outString = ReadStringEx(0, DevicePath);
			j9.CloseUsbHandle(DevicePath);
			if ((j9.get_LastError() == 0) && (outString.compareTo("abc") == 0))
			{
				return 0;
			}
        }
        return -92;
    }

    public int CheckKeyByEncstring()
    {


        int n, ret;
        String DevicePath = "";
        String InString;


        int number1=(int)(Math.random()*65535)+1;
        int number2=(int)(Math.random()*65535)+1;

        InString = (new   Integer(number1)).toString() + (new   Integer(number2)).toString();

        for (n = 0; n < 255; n++)
        {
           DevicePath= j9.FindPort(n );
            if (j9.get_LastError() != 0) return (int)j9.get_LastError();
			if (Sub_CheckKeyByEncString(InString, DevicePath) == 0)
			{
				return 0;
			}
        }
        return -92;
    }

    private int Sub_CheckKeyByEncString(String InString, String DevicePath)
    {

        int ret;
        String outString = "";
        String outString_2;
		outString = j9.EncString(InString,DevicePath);
		if (j9.get_LastError() != 0) return (int)j9.get_LastError();
		outString_2 = StrEnc(InString, "BAB416B821B3932C2447D54CD65C9559");
        if (outString_2.compareTo(outString) == 0)
        {
            ret = 0;
        }
        else
        {
            ret = -92;
        }
        j9.CloseUsbHandle(DevicePath);
        return ret;
    }


	public int CheckKeyByEncstring_New()
	{
		int n, ret;
		String DevicePath = "";
		String outString = "";
		int myrnd = (int)(Math.random() * 500);
		String[] EncInString ={ "20281","25902","2174","9988","2576","7444","18323","21867","23523","12416","4761","1156","15903","23347","15943","7714","15182","9616","14712","15798","18712","22168","14118","12884","16969","1519","30827","8363","202","19924",
"13954","17680","6053","7468","11460","21874","11524","10615","17066","871","29744","216","21968","7709","18326","15376","9200","21607","25277","20610","21729","5817","15441","560","9377","6435","27","30138","11591","30039",
"10500","25189","20751","27817","15128","25618","17489","18953","7552","27970","14217","25610","5254","22808","8528","16093","23444","7509","10336","20053","24372","7260","11667","22499","5905","5935","30179","29850","32755","16239",
"29803","13100","13766","26974","13412","23019","11667","24032","25383","18632","3972","19573","31280","31573","12515","23872","2328","10950","11803","25346","8089","4075","9396","11550","22413","17718","3418","31125","32494","18618",
"13781","1803","25047","7721","23312","18112","13440","4309","25366","11926","7493","5551","14096","11024","24223","19785","15689","12624","8488","9686","29480","28951","23962","7464","10043","9928","26319","8881","21289","3429",
"5058","6530","5566","28815","2443","31309","19683","24200","9573","5478","20386","31284","1707","29884","18469","27923","14550","24036","11702","31048","32127","29710","24255","11156","13923","31245","23242","11610","28504","13395",
"7298","13980","2140","27377","5040","8187","32646","2970","16189","5306","23314","27551","26421","25786","13145","10740","30401","30334","23764","12584","30251","22824","12831","22895","9438","30329","32243","10907","13154","25812",
"1323","15902","7522","22843","12479","16649","9129","14671","22474","5647","26143","19795","10631","6017","7633","4649","14159","31058","30437","11090","7836","19220","2729","29936","21255","6648","31107","13766","2125","13009",
"9473","28982","15428","1041","2507","22850","24809","8137","14762","24715","9814","23979","30089","27732","25795","7435","26483","9855","9868","9945","31889","28556","21034","12199","24366","28832","29751","31144","4274","19835",
"10605","5807","9129","30336","10406","18987","5563","6833","27868","2864","18867","14767","32553","9840","8572","21949","24776","61","14367","17852","5394","30343","15302","10032","19329","25315","26555","28728","10671","15489",
"7785","8601","13654","23092","9048","6323","24144","21613","30003","393","10391","1856","18373","26811","30277","13404","7671","28046","29077","17686","979","5091","5856","11358","26754","13883","24223","26822","6225","6073",
"1903","9858","22182","5662","7","354","6159","31692","28993","26328","23603","29127","26650","6135","10206","4528","8106","19313","7929","6087","27434","28567","16014","13553","16374","3165","14023","174","24454","17746",
"25837","2849","8567","31658","28013","3851","23935","4151","30158","17359","30075","17771","32443","20334","32612","16727","24063","22667","3926","12206","22659","14440","8583","961","23633","19687","9300","23171","23187","27272",
"8758","31877","16787","28272","3015","32762","5820","28767","8640","2741","12438","5305","32509","13349","4300","32381","17016","1887","24104","24911","22857","9490","32405","13169","26795","1427","20764","32708","22521","23249",
"2024","22476","31404","4705","8769","26024","23134","30579","1682","7709","8393","29914","15461","4747","8647","30471","18020","25332","1363","28173","7258","20475","4485","28574","17712","27874","5273","30987","4336","29066",
"28391","20808","29379","11383","15595","2789","31477","5321","8510","9748","28911","31809","11930","21160","3389","24901","29145","21010","21381","24787","7158","31077","3220","18575","19465","21331","24658","18619","31053","25133",
"4043","17977","32028","487","20264","19594","15602","27152","16307","8145","29797","20444","2519","28367","7987","10269","5916","9447","819","2373" };
		String[] EncOutString ={ "CE0298E81C9410C1","EE286706493035F1","DF7000901F76EE92","D450F5C0B0D2629B","E98C86478AA18BA6","E3F8E2D667705A02","834F0104BC1CF4B3","4B5FDC531227528B","9FB4572AD4CF2683","5EC2EC3E9F46C661","E8932E0D76D4474C","84FE781BE3EDE746","36CD2BBE0FDD1D8A","F3EF6A28D2B3F053","8740F8520598FA2C","6A7F6A85B13BBAC2","430F2FE45193DA14","174CFF2C43EA2251","C8FE2DDD5CFF55B5","72EDD2DD29ACD4E9","4B07F57AC5428707","7E2BC165A8105EAE","EE7655D83267B637","7D6F1719E41221EB","47BDEEB5CC40476C","60BBB7B878E469EF","2C1267732FF8D887","E9CEB18C85E396C9","8CAF41FCC60364FC","F0D32FF4FFF616B4",
"9A8756089F0D8F6C","B489BB702FFD3582","79E481406CB34028","705E3FEA5D1A7F98","1918489963FE743A","0FD017AAE6C9855F","3FCC569F5B7188D0","6140E63A0B270A5F","1760DC570A337537","DEA51903802247EC","BF8A64AB20FAACC6","AE5DE905BC1A2C77","0819C89DB0261501","1EB1313C531CE926","7A10C9B54E0A1596","8348701085F67AA1","C52876F01E20E6A6","17620FBBE925DF86","945390857C4FCD23","54A92AB45C38F99C","E22A89CC35BE816E","D5FB9EE4F5AC22EC","DDF1047D99AB459F","1415E9E94598E87F","8C203557EB11E490","4B95C8EE78553D7F","AADCAFB486D834F9","DEC9E38D4FC4336A","B1B8430B12E805B8","9E9022E62D8574C1",
"C909D9AC01AAFD9A","DD765EDEA4647609","EA04F45D22020055","68BB23A1A7BD3847","43205484FABFCEDB","7F6AAB3EF6BE48C1","BD3F8458204CEEDA","239D777E86E16C15","F39FBFBC15669BAE","A19674E158888DD1","C114E6090511D52B","0C3869A77DB44F54","4C9E1AD2F98511C1","9B895FF7718EFC93","54CEF0AD687137D7","ED4E876DF094F550","CA7B70A16985FC60","7B30E9B9D4ED8B7F","F70DB58B29B5365A","1AA04C29514A9D38","149F65BB3C8BF8F4","157918F15D5C1483","C06D7AD14F533983","453294D50A9BB96A","182DAB10FF3808ED","9097C72F7D2F672E","CFF806DB38DA3F88","2A0676780C0C1371","2BF0F81D591F3CD6","FCB3C8EB0C6AA861",
"D9B25391A0EA5AB8","B41D45CB58F68189","4AD5050AF7A53E47","7DF722C5A5D593D2","5AE6FB666F2E0C37","040FE6F24133E775","C06D7AD14F533983","D5EC3F0C26BD8E38","0019BE0569F7E47F","279DDE432A96214F","E931200197B67ECC","9AC5E591E7F9F0AE","D67846FA9138D4BA","05DDD7D2EE1DA476","6F9EEBB166CBC171","5ABCACB463254292","D72DF4071C6391A8","4C06045EA3FFBF3F","62E1BB46612B6DB9","886CD6D916367A63","895934299E9155EE","DE64B465BBB4FD4A","7D4D5B4BC3C66F35","799D1F95CBC3D369","D84DD2EB4B4AE8E2","BE79E4F6183E8181","D1F247149CBBD926","831051AECB0EE5FC","CA8ED46ECD10D8A8","E7214B212492B995",
"1EEF995D5DD6F50F","8116E3D66ACAB126","2FA05F4B0457F2DA","8C8ECA77A570476A","9F581C5D9DA439E3","523698D636DE6258","D8574C03D5146FD7","2242505099CD1B66","1DAB1A2D72F43E9D","3D4B3B7864754B1A","1233CDCFDABE15A3","64E8F5C100BFE119","7AC2C30D0A3263D8","349AAEEFE748DD9A","6EF8622462807379","86720E1CFCCA8380","043F94E3F62759E3","45A39A72B1530002","2A8631FBF236CBF6","BB5E444DDDEA8D69","6203F92600D84F14","FC4C96DB45E04DCE","F2B3ED90E9F40A50","3A07084C20995F15","04940F3182EED685","6CCECA9D5F5F486F","E1482F21DCC893B9","9AA238E26E5E61F6","D52485B2A7F1165E","5D1F430E0F99B7A4",
"9B87429D4E1D85AF","FC599F82F4713AAA","109CF85D4D3C0EC8","C598D061591B12C5","DA2201D420B03134","4094625B161B332E","28421A059E3F5E47","CC6D7DDF340601B9","0FC90538B5FECA9C","6F4B3A302DBA6F82","A4D09ECBB304A3C7","FE9E50C26B1EB05B","EF9E1BD3E7C841E3","6AEC325A2BB635A8","A34C6A7925AA6E30","20BB392AB5450688","9F450F524F0EC80C","378CB27669B6AE33","62A23AFAA56365F7","6E7DC21D935F8D88","06B3132D8834F042","0D24898152B0BF8A","0E28E14F98EDB55A","B2B45C62ED70229C","E49CC6CAF1C078E4","9053045E1E37AC93","0BE0AD62F648F1A1","9D8FF975908D0AAF","5F1E0DC4D3D23F8C","776F1ED9BC0F3F8B",
"39B43181EEEAE29F","8B22AC29D7B9AEC4","B2945FAD331E3C5F","4516267CDD1630CC","7E8F777332E547E6","0DA3230C00FE1437","6DED08354B5FE532","FAF040B803F12709","85254882F26504BA","D98F46124549D92B","72EE21F6015244D8","DC57DBBEF8E3B9BB","E1880671A0FCD7D2","6B0B31ED9A88183C","0691F86B132820FC","BDE0CB653B3B629E","BC10CBFCF8357698","D36817B41EF57C06","9A49BEDDFDB4367D","E0197A4991C7FF0F","5EF64509873BF019","570BBB79ED98932B","3447C22CC2224CD2","AF9B2389ABD3C0FA","DD28273369AA44E7","A935796823A6A1C0","1B3F04E6FC2E2678","9E9230D0DB734E17","2A18B983A5F1345C","60E43218A33E176A",
"B38F5D408E094B12","B5BD5F5ACAC102B3","F62115AF91A704FD","77947FB298FF4593","E1D90885821E9AE9","F25707987369CED6","861FF06FCED9F7C6","C628D1383ED8E733","CC9FC8C2EF311658","027A6455F7D57276","6621519EA57C7987","A9B075FE2B407225","C2DCDB3662D7CE2C","A71CDDAEAF55F38F","4A48BAC6DC6E73E8","A3B276CBBA3630EB","E7A5DB6DA714EC26","CB9E74F3BFEC3982","427AA755652298C1","F1B2372195FDBE2E","E4222709A91BC33A","CF8E579067E9482F","9E0739F3711E3052","B37B99AC41999CE7","AA61007671E0B23A","E55BC3C6396E8DCB","7E34BB8263FA4CF5","4AD5050AF7A53E47","CC0B0002383843EC","5A6BC11D2D970AEC",
"119EB69563817774","D5980969370696AA","2F9C8EB320E6DD67","569A0498C2BBB4FF","9A05148DC8FD2F3E","E780251618C58200","2D9AEACC6FA76F52","BDF09D192B830E35","34F201F1E8942676","87454290CCFAD5BA","91A9F018C70F0836","BEA31C13D64FC60B","D58162EB3275CA2A","DCD3954285487132","3C6A5E63B1871FCA","9A9754548E6558B3","1F5AA4045B144765","3E6237C673D93042","C12B74BBF79498BC","4EEB4C963C0BCAC7","63B17933937BD376","68A4AFC46549D7EE","5165CFAC958DD7D6","DED7126A54EA7B05","DE15508E273F0C3E","9C7866BE23E30D6F","464EC8545962DA40","D24454CF15A53286","0807225348040904","290CFF91EFEA66E5",
"8CF982D4540E4ECC","6FDFF6712CE7FE76","861FF06FCED9F7C6","F4B686E565A127D7","338BB782372790AD","96EE41F4CE3CDD8D","DAD945BD64770D29","4BA175BD020D515D","08A225F50B9A6FA1","88334D8A0DC417E4","E4D994188100E625","E8BFFF028254CEE1","63575D30031AFBA8","E38E2EF4F984E64A","661EC84DD6FD8A63","01125C03AF8FC141","AB4965F3A375F8AA","75C5668C2D75036C","7EBD72A552358DE9","4A550843F1166D0B","3CA94B3ED0DE06B6","DEF74950EEE6E860","56502281100B78C2","B49CC0BE1178ECE7","D7F905E8BD76C556","8F91D7E982FE3CFB","D52D7EFC2A30DE6E","6CD9CA32ADBD04BF","CA60148990F66E1D","2398DA3B908BC88B",
"851004B2C83D959A","56238EB15CF2EE03","9B99F3E9B8FA4964","4F0E21A0C8156F4B","0B12755566C8C2E3","2297B074AB5F35A1","EFD55B5B21F5797B","53DEBF044FDEFA8F","BAF0E7B24D3D2771","82EFB703A8BB1A16","F6933073788F2571","799E8C8CDC8BE0E8","7F65C6D8B2CD6B42","F6A578849D2C92A3","9E29435A9AB3C643","0CBE0D22B09F53CB","F86F4DE4569C43D2","313FF725984F1844","ABE5822E7B621F95","2FC21C81E533AB3A","6F4D3E06EDF4750F","4AB3AF4B44A6DD2B","A272E2378DBD87A8","E51743B94A7266FF","D2F42FB2700A6FD8","7378D5C8DA86776F","6EF8622462807379","81482B93C9699F39","DC777E0CD5BDAFC7","95CF63580E7D4380",
"5DE1A2D7B1BF66BC","7134B20412417FB6","91F3021DF2D400CA","C3A9871079DEF94A","4670D7BBA2213E9A","EEC7E57E9B43CE1B","9370B21712838436","66FED3454CC2FBA6","A4C93544232B9CA0","D73D02EDB9F0AEAF","7B07EBD89B06CFD5","C151F6B4BC68D38A","7DB8B23B60CE7448","F34647430AEAA76F","CF490DB458EF9158","DA1B84B1D78A106B","FAF5FEA49F686B1E","655398891DCCD13B","5F7E65D0A3DD154B","8C647E613BAEA727","6AEB222C9606BF52","60632BB4E28EE29A","D393E248E2635ECE","D2CF3305DBF0422C","633BBDA6AB5CAD42","A639EEF1061CCC6F","0C4370165F4D7BE7","757BD5C185ED30E2","61810E00C840339E","3D920A17F3533B14",
"1D9979B59AC02FFF","5E5CB078DCEEAD6A","D942EF77CC678F72","51276724D93267B3","6682EC45A2CAD929","CF877967C1CEA6D9","DFAE1B524501D3C3","77A9A971B0CAE59E","A287FFC2E8B5E9BD","38E5F54B54E7F075","DA4C176C0AF243C0","105974D6D6153B15","28299ADFABBC4A69","759CA0F0AF47B092","C19769303D3B910F","81866A0037A08CBD","2FCC467C896CDF52","410A900DEECF670A","B0EC159419C252B7","1A1DEFB5DD690E55","0A36E1ADB1F8CA80","EB7BA052AF12CCDF","A24331A59368654A","9F49DF9D65219164","3561C1515B12EACE","028ED9105BF53471","B7E9E1CC1E0C25CE","5FFADAFB952DA64A","93088F62C8E7274F","CE4A6A2FAA12006B",
"F5B0255C3A1E69D1","81735FEDFCE75473","1F16CD1A487DED78","59E7A5E1DDAE4CD5","C3D973CAB28C6DA0","6D3C94E830770684","2A50C4FDE6611A56","0281FE2A29BE7B3B","05E6DF486B99BD72","22DE1B3578BDB1F8","5C0E5FB9433DEBD7","7468E3BE063CADF8","2F2154D33B20D3D1","63B9272FF6F0FF52","794E41484AC5DBBA","A003F0D8EE9D0EA0","6501F75E02B0E7E1","2728018321509152","F33DF6E9004F6386","67029713D47314B4","4E9C44FBF878C812","D2B70671178DF606","1E9BB7F0C881802A","7B0DE04833A2C106","73545073D522721D","78508F673D06E1CE","CA8A004DF798C6DE","5B2645E63550260D","FBD2EF6861060FC0","73BD2E589D29E3F1",
"EF12F0D4BEBB2776","C16EA61316D8C79A","E1AE0B35CD5357AE","2D1B9C0D1A918575","B5BD1B99865E2EDA","99D1F13F14A7E665","F3A8F666E495C864","24C3C7AD89B54128","54B3A2694DB6C2F3","1EB1313C531CE926","30FB572B50A782CD","5F2D2B2B57188AC5","CF5E98703147FCA7","FB3DF3F2B06C3D14","EF61AD57FFF394E0","E28B3E8190A30952","F93728D5898292D2","8076BA8A11FA0CCB","94458D5B7BB98B11","328BBB71D16D08F2","1D28795614C4F7B5","EBE0A389452C749E","83ADE489F56A0362","10E76CF01B9010B5","937D3026B6350A37","57020C95FE6E06CD","0F8A3618A062DF54","5BAAA669FFFE3C99","77AC94986E91105D","6DF43FAE22AF6B3D",
"A7DAFEFF3F7A5311","59A19D800AA1A3F8","C9850A631A1B89BD","D750F9DDAF9CAD19","E3538D4C7A9D8727","18E7D73BA8B63CDE","CEC1791368E79DCE","2AE56A2EB21719B8","B5E3C9E6E4A079EC","195057B1DFF4650A","9084B0DAB002862E","AD5BB143F763BA3B","2186EE8056654217","06ADC0440D110060","BE0C3B397CD2F289","F8F17EA4C75A40C5","CD47317E5A3199CE","62409BADCFCD4727","986BA3BFF19E458B","17282C2F7961148C","6CE5C8A34C4E7D58","D8C77F23471E45E8","0EDB904F92456F2E","B1EF1751D98C441C","A57763E6E126B36C","D183138A67819580","2E9BE1884017E714","0C79A85401407581","0A4E13ACBCFF7EAD","8E1E0DE850449BC2",
"537A3CEBBA1ED4F0","524B023A6BFBC196","003E602517338CB0","D214816A7FBE9C4E","D8F4BAEEE7EF0DAC","5E0F2BB6A0140D22","2B29AF009E71F334","E7C99231B64B3FC4","9507AE56B180F06F","ABBA28ECAB2049CC","725EFD92729AEFE6","DEB49898BE60E49A","E26E1B1FFA185DBD","0C0FA781E8A5BD64","392795ADF59C9465","A48D999ADD3020A3","7C6039884CEE31B8","D3352CF8380EADC0","8631FA401F03C95B","9E7E34FA684686F6" };



		for (n = 0; n < 255; n++)
		{
			DevicePath = j9.FindPort(n);
			if (j9.get_LastError() != 0) return (int)j9.get_LastError();
			outString = j9.EncString_New(EncInString[myrnd], DevicePath);
			j9.CloseUsbHandle(DevicePath);
			if ((j9.get_LastError() == 0) && (outString.compareTo(EncOutString[myrnd]) == 0))
			{
				return 0;
			}
		}
		return -92;
	}


}
